//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
    gridBody: '',
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  data () {
    return {
      tabledata: [],
      // getVueDictionary: []
    }
  },
  buttons: { view: [], box: [], detail: [] },//扩展的按钮
  methods: {//事件扩展
    getFormOption (field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        })
      })
      return option;
    },
    getDetailOption (field) {
      let option;
      this.detail.columns.forEach(item => {
        if (item.field == field) {
          option = item;
        }
      });
      return option;
    },
    onInit () {
      this.maxBtnLength = 5;
      //点击单元格编辑与结束编辑(默认是点击单元格编辑，鼠标离开结束编辑)
      this.detailOptions.clickEdit = true;
      // label宽度
      this.boxOptions.labelWidth = 100
      // 弹框宽高度
      this.boxOptions.width = 1000
      this.boxOptions.height = 530;
      // 开启单选
      //;
      // 内容超出后自动换行
      this.textInline = true;
      let cinemaareaid = this.getDetailOption('cinemaareaid')
      let parm = { "page": 1, "rows": 30, "sort": "Id", "order": "desc", "wheres": "[]" }
      this.http.post('/api/cinemaVenue/getPageData', parm).then(res => {
        cinemaareaid.bind.data = res.rows.map(i => {
          return {
            key: i.Id,
            value: i.venue
          }
        })
      })
      let is_open = this.getFormOption('is_open')
      let distributorNews_id = this.getFormOption('distributorNews_id')
      let pram = { "page": 1, "rows": 30, "sort": "createDate", "order": "desc", "wheres": "[{\"name\":\"distributorType\",\"value\":\"2004\",\"displayType\":\"select\"}]" }
      this.http.post("/api/DistributorNews/getPageData", pram).then(res => {
        distributorNews_id.data = res.rows.map(i => {
          return {
            key: i.id,
            value: i.distributorName
          }
        })
      })

      is_open.onChange = (v) => {
        if (v == 1) {
          distributorNews_id.hidden = false
        } else {
          distributorNews_id.hidden = true
        }
      }
    },
    rowClick ({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
  
    modelOpenAfter (row) {
      let distributorNews_id = this.getFormOption('distributorNews_id')
      if (this.currentAction == 'Add') {
        this.editFormFields.is_open = 0
      } else {
        if (row.is_open == 1) {
          distributorNews_id.hidden = false
        } else {
          distributorNews_id.hidden = true
        }
      }
    },
    addBefore (formData) { //新建保存前formData为对象，包括明细表
      return this.veriFromTable(formData)
    },
    updateBefore (formData) { //编辑保存前formData为对象，包括明细表、删除行的Id
      return this.veriFromTable(formData)
    },
    // 保存前编辑  
    veriFromTable (formData) {
      // 将从表中的日期切分为开始日期 和结束日期
      console.log(formData.detailData,"formData")
      formData.detailData.forEach(item => {
      if(item.timeContainer==undefined){
       item.timeContainer=""
      }else{
        if (item.timeContainer.length > 0) {
          item.begin_time = item.timeContainer[0]
          item.end_time = item.timeContainer[1]
        }
      }
    
      })
      return true
    },

    searchDetailAfter (data) {//查询从表后param查询参数,result回返查询的结果
      // console.log("从表数据", data);
      // 将从表中的开始日期 和 结束日期合并为起止日期
      data.forEach(item => {
        item.timeContainer = []
        if(item.begin_time==null&&item.end_time==null){
          item.timeContainer=""
        }else{
          item.timeContainer.push(item.begin_time)
          item.timeContainer.push(item.end_time)
        
        }
 
 
      })
      return true;
    },
  }
};
export default extension;
